//e
#Title[Tv4]
#Text[]
#Image[]
#BGM[]
#Player[FREE]
#PlayLevel[]
#BackGround[]
#ScriptVersion[2]

script_enemy_main {

    // ֐̎荞
    #include_function ".\usershot\lib_usershot.txt"
    #include_function ".\effectdata\Obj_EffectALL.txt"

    // XNvg܂ł̃pX̎擾
    let csd        = GetCurrentScriptDirectory();

    // G摜̃pX
    let imgBoss    = csd ~ "img\ExRumia.png";

    // G̖O摜̃pX
    let ename      = csd ~ "img\ename.png";

    // ʒu̐ݒ
    let xIni       = GetCenterX()  + 1;
    let yIni       = GetClipMinY() + 120;

    // e摜̃pX
    let shotData   = csd ~ "\usershot\data_usershot.txt";

    // G̃l
    let enemyalpha = 0;

    @Initialize {

	LoadGraphic(imgBoss);
	SetTexture(imgBoss);

	SetLife(1200);
	SetDamageRate(0,0);

	MagicCircle(false);
	SetRateScoreSystemEnable(false);
	LoadUserShotData(shotData);
	SetEffectForZeroLife(80, 224, 1);
	SetShotAutoDeleteClip(96, 96, 96, 96);

	MainTask();

    }

    @MainLoop {
	if(enemyalpha==255) {
	    SetCollisionA(GetX, GetY, 32);
	    SetCollisionB(GetX, GetY, 32);
	}

	yield;
    }

    @DrawLoop {
	SetAlpha(enemyalpha);
	DrawGraphic(GetX, GetY);
    }

    @Finalize {
	DeleteGraphic(imgBoss);
    }

    // C^XN
    task MainTask {

	yield;

	StandBy();
	Shot1();
	wait(120);

	while(GetLife>700&&GetTimer>30) {
	    loop(3) {
		Shot2(5);
		if(GetLife>700&&GetTimer>30) { wait(40); }
	    }
	    if(GetLife>700&&GetTimer>30) { wait(120); }
	}
	DeleteEnemyShot(SHOT);
	wait(60);
	while(GetLife>200&&GetTimer>30) {
	    loop(3) {
		Shot2(2);
		if(GetLife>200&&GetTimer>30) { wait(40); }
	    }
	    if(GetLife>200&&GetTimer>30) { wait(120); }
	}
	DeleteEnemyShot(SHOT);
	wait(60);
	loop {
	    loop(3) {
		Shot2(6);
		wait(40);
	    }
	    wait(120);
	}

    }

    // ʒuֈړ
    function StandBy {
	Slow(0);
	Diffusion01(40,255,255,255);
	wait(60);
	SetMovePosition02(xIni,yIni,1);
	wait(60);
	Concentration05(120,255,255,255);
	wait(120);
	Explosion02(GetX,GetY,255/60,255,255,255,20/60,60);
	EnemyMarker01();
	DrawEnemyName(ename,0,16,true);
	Aura1( 8, 64, 64,128);
	enemyalpha = 255;
	SetGraphicStop();
	wait(60);
	SetDamageRate(15,0);
	SetGraphicPose();
	Aura2(60,160, 64, 64);
	MagicCircleEx2(true);
	SetTimer(120);
	SetScore(1000000);
	CutIn(YOUMU, "uv", "", 0, 0, 0, 0);
	MotionBlurEx(SHOT,9999,144,ADD);
	DrawTimer();
	DrawTimerEx(2);
	LifeBar_A_02(3, 1.0, 0.0, true);
	LifeCircleBar_A(1.0, 0.0, true);
	wait(60);
    }

    // U1
    task Shot1 {

	let long     = 80;
	let speed    = -2;
	let angle    = -90;
	let addangle = 0;
	let addspeed = 4/60;
	let maxspeed = 4;
	let delay    = 12;

	let eff     = dPURPLE02a;
	let graphic = US_BALL_M_A_PURPLE;
	let bomb    = false;
	let time    = 0;

	while(GetLife>200&&GetTimer>30) {
	    CreateObjShotC_T04(GetX()+long*cos(angle), GetY()+long*sin(angle), speed, GetAngleToPlayer, addangle, addspeed, maxspeed, graphic, eff, delay, time, bomb);
	    angle += 360/10;
	    wait(6);
	}
    }
	

    // U2
    task Shot2(pangle) {

	let way      = 5;
	let long     = 20;
	let speed    = rand_int(1,2);
	let angle    = rand_int(0,360);
	let addangle = -speed/2;
	let addspeed = -speed/60;
	let maxspeed = 99;
	let delay    = 12;

	let eff     = dYELLOW13a;
	let graphic = US_RICE_M_YELLOW;
	let bomb    = false;
	let time    = 0;

	loop(10) {
	    loop(way) {
		CreateObjShotC_T02(GetX()+long*cos(angle), GetY()+long*sin(angle), speed, angle, addangle, addspeed, maxspeed, graphic, eff, delay, time, bomb);
		CreateObjShotC_T02(GetX()+long*cos(-angle), GetY()+long*sin(-angle), -speed, -angle, -addangle, -addspeed, -maxspeed, graphic, eff, delay, time, bomb);
		angle += 360 / way;
	    }
	    angle += 360/pangle;
	    wait(3);
	}
    }

    // OtBbN̐ݒ
    sub SetGraphicStop  { SetGraphicRect(  0,  0, 64, 64); }
    sub SetGraphicPose  { SetGraphicRect( 64,  0,128, 64); }
    sub SetGraphicLeft  { SetGraphicRect(128,  0,192, 64); }
    sub SetGraphicRight { SetGraphicRect(192,  0,256, 64); }

    sub SetGraphicMove {
	if(GetSpeedX <  0) { SetGraphicLeft(); }
	else { SetGraphicRight(); }
    }

    // w t[ҋ@
    function wait(w) { loop(w){ yield; } }

}